package com.zlt.bkparking.controller.parking;

import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.dto.ParkingOrderDTO;
import com.zlt.bkparking.dto.VipTypeDTO;
import com.zlt.bkparking.mapper.VipTypeMapper;
import com.zlt.bkparking.service.ParkingVIPService;
import com.zlt.bkparking.vo.ParkingLotVO;
import com.zlt.bkparking.vo.ParkingOrderVO;
import com.zlt.bkparking.vo.Result;
import com.zlt.bkparking.vo.VipTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname ParkingVIPController
 * @Description TODO
 * @Date 2022/10/4 20:09
 * @Created by ${Lijijun}
 */
@RequestMapping("pkvip")
@RestController
public class ParkingVIPController {

    @Autowired
    private ParkingVIPService parkingVIPService;


    @GetMapping("viptypes")
//    @CrossOrigin
    public Result allParkingVipTypes(){
        List<VipTypeVO> vipTypeVOList = null;
        try {
            vipTypeVOList = parkingVIPService.allParkingVipTypes();
            return Result.ok("当前停车场的vip类型查询成功",vipTypeVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ok(e.getMessage(),vipTypeVOList);
        }
    }

    @PostMapping("add")
//    @CrossOrigin
    public Result insertPKVipType(/*@RequestBody*/ VipTypeDTO vipTypeDTO){
        Boolean bool = null;
        try {
            bool = parkingVIPService.insertPKVipType(vipTypeDTO);
            return bool?Result.ok("停车场Vip类型添加成功"):Result.error("停车场Vip类型添加失败");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

//    @GetMapping("userOrder")
    @PostMapping("userOrder")
//    @CrossOrigin
    public Result allParkingOrder(ParkingOrderDTO parkingOrderDTO){
        PageInfo<ParkingOrderVO> parkingLotVOPageInfo = parkingVIPService.selectParkingOrders(parkingOrderDTO);
        return Result.ok("当前停车场的Vip用户的消费情况查询成功",parkingLotVOPageInfo);
    }

    @PostMapping("userOrders")
//    @CrossOrigin
    public Result ParkingOrderByAuId(ParkingOrderDTO parkingOrderDTO){
        PageInfo<ParkingOrderVO> parkingLotVOPageInfo=null;
        try {
            parkingLotVOPageInfo = parkingVIPService.selectParkingOrdersByAuId(parkingOrderDTO);
            return Result.ok("当前停车场的Vip用户的消费情况查询成功",parkingLotVOPageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage(),parkingLotVOPageInfo);
        }
    }

}
